
#ifndef _SPARSE_MATRIX_ARR_
#define _SPARSE_MATRIX_ARR_

#ifndef elem
	#define elem double
	#define elem_scan_format "%lf"
#endif

#include <stdio.h>
#include "../common/dynamic_int_arr.h"

typedef struct
{
	int n; /* size */
	int* rowptr; /* pointers to where rows begin in the values array. */
	int* colind; /* column indexes */
	elem* values;
} sparse_matrix_arr;

sparse_matrix_arr* allocate_sparse_matrix_arr(int n);
void free_sparse_matrix_arr(sparse_matrix_arr* matrix);
void mult_sparse_arr(const sparse_matrix_arr *A, const elem *v, elem* result);

sparse_matrix_arr* sparse_matrix__read_from_file(const char* from, int n);
sparse_matrix_arr* sparse_matrix__read_from_stream(FILE* stream, int n);

sparse_matrix_arr* sparse_matrix__make_sub_matrix(const sparse_matrix_arr* matrix,
												  int* indices, int indices_count);

void sparse_matrix__print(const sparse_matrix_arr* matrix, FILE* stream, const char* element_format);
void sparse_matrix__print_integers(const sparse_matrix_arr* matrix, FILE* stream);
elem* sparse_matrix__to_array(const sparse_matrix_arr* matrix);
elem sparse_matrix__sum_row(const sparse_matrix_arr* matrix, int row);
void sparse_matrix__mlpl_matrix_times_vector(const sparse_matrix_arr* matrix,
											 const elem* vector, elem* result);

elem sparse_matrix__get_cell(const sparse_matrix_arr* matrix, int row, int col);

dynamic_int_arr* sparse_matrix__search_for_singletons(const sparse_matrix_arr* matrix);

#endif /*  _SPARSE_MATRIX_ARR_ */

